package com.health.mapp.bean;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.health.pay.tencent.common.Configure;
import org.codehaus.jackson.annotate.JsonProperty;

import com.alibaba.fastjson.annotation.JSONField;
import com.health.mapp.utils.Response;

/**
 * @author YYY-Work
 * 
 */
public class PayControllerWXMiNiResp extends Response {

	private String appid;
	private String noncestr;
	@JsonProperty("package")
	@JSONField(name = "package")
	private String packageName;
	private String partnerid;
	private String prepayid; // String Y 微信预支付交易会话标识
	private String sign;
	private String timestamp;
	private String key;

	private String signType;
	private String payAmount;


	public String getSignType() {
		return signType;
	}

	public void setSignType(String signType) {
		this.signType = signType;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getNoncestr() {
		return noncestr;
	}

	public void setNoncestr(String noncestr) {
		this.noncestr = noncestr;
	}

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getPartnerid() {
		return partnerid;
	}

	public void setPartnerid(String partnerid) {
		this.partnerid = partnerid;
	}

	public String getPrepayid() {
		return prepayid;
	}

	public void setPrepayid(String prepayid) {
		this.prepayid = prepayid;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(String timestamp) {
		this.timestamp = timestamp;
	}

	public String getPayAmount() {
		return payAmount;
	}

	public void setPayAmount(String payAmount) {
		this.payAmount = payAmount;
	}


	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			Object obj;
			try {
				obj = field.get(this);
				if (obj != null && !field.getName().equals("errorCode")
						&& !field.getName().equals("errorMsg")) {

					if (field.getName().equals("packageName")) {
						map.put("package", obj);
					} else {
						map.put(field.getName(), obj);
					}

				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return map;
	}


	public String toUnencryptedString()
	{
		 String signParam = "appId=%1$s" + "&" +
				"nonceStr=%2$s" + "&" +
				"package=%3$s" + "&" +
				"signType=%4$s" + "&" +
				"timeStamp=%5$s" + "&" +
				"key=%6$s";
		String unencryptedString=String.format(signParam,appid,noncestr,packageName,signType,timestamp, Configure.getKey());
		return unencryptedString;
	}

}
